//
//  ViewController.m
//  128
//
//  Created by boom on 2017/5/23.
//  Copyright © 2017年 boomLi. All rights reserved.
//

#import "ViewController.h"
#import "TestObj.h"
#import <JavaScriptCore/JavaScriptCore.h>

@interface ViewController ()<UIWebViewDelegate>

@property (nonatomic, strong)UIWebView* webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    TestObj * phone = [[TestObj alloc] init];
    phone.sum = 123;
    
    [self.webView sizeToFit];
    self.webView.delegate =self;
    [self.view addSubview:_webView];
    
//    JSContext *context=[_webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//    context[@"sum"] = test;
    
    NSString* url = @"http://www.nbinbi.com/new/newweixin/128taocan/128xiangqing.html";
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
    [_webView loadRequest:req];
    
    JSContext *context=[_webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    context[@"phone"] = phone;
    
}

-(UIWebView *)webView{
    if (_webView != nil) {
        [_webView removeFromSuperview];
    }
    _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    return _webView;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
